/*
 * @Author: zi.yang
 * @Date: 2021-10-02 23:01:13
 * @LastEditors: zi.yang
 * @LastEditTime: 2021-10-02 23:07:46
 * @Description: In User Settings Edit
 * @FilePath: \ziYangPM\src\Utils\getOS.js
 */
function getOS () {
  const { userAgent } = navigator
  const isWin = (navigator.platform === 'Win32') || (navigator.platform === 'Windows')
  const isMac = (navigator.platform === 'Mac68K') || (navigator.platform === 'MacPPC') || (navigator.platform === 'Macintosh') || (navigator.platform === 'MacIntel')
  if (isMac) return 'Mac'
  const isUnix = (navigator.platform === 'X11') && !isWin && !isMac
  if (isUnix) return 'Unix'
  const isLinux = (String(navigator.platform).indexOf('Linux') > -1)
  if (isLinux) return 'Linux'
  if (isWin) {
    const isWin2K = userAgent.indexOf('Windows NT 5.0') > -1 || userAgent.indexOf('Windows 2000') > -1
    if (isWin2K) return 'Win2000'
    const isWinXP = userAgent.indexOf('Windows NT 5.1') > -1 || userAgent.indexOf('Windows XP') > -1
    if (isWinXP) return 'WinXP'
    const isWin2003 = userAgent.indexOf('Windows NT 5.2') > -1 || userAgent.indexOf('Windows 2003') > -1
    if (isWin2003) return 'Win2003'
    const isWinVista = userAgent.indexOf('Windows NT 6.0') > -1 || userAgent.indexOf('Windows Vista') > -1
    if (isWinVista) return 'WinVista'
    const isWin7 = userAgent.indexOf('Windows NT 6.1') > -1 || userAgent.indexOf('Windows 7') > -1
    if (isWin7) return 'Win7'
    const isWin10 = userAgent.indexOf('Windows NT 10') > -1 || userAgent.indexOf('Windows 10') > -1
    if (isWin10) return 'Win10'
  }
  return 'other'
}

function getBrowse () {
  var browser = {}
  var userAgent = navigator.userAgent.toLowerCase()
  var s;
  // eslint-disable-next-line no-unused-expressions,no-cond-assign
  (s = userAgent.match(/msie ([\d.]+)/)) ? browser.ie = s[1] : (s = userAgent.match(/firefox\/([\d.]+)/)) ? browser.firefox = s[1] : (s = userAgent.match(/chrome\/([\d.]+)/)) ? browser.chrome = s[1] : (s = userAgent.match(/opera.([\d.]+)/)) ? browser.opera = s[1] : (s = userAgent.match(/version\/([\d.]+).*safari/)) ? browser.safari = s[1] : 0
  var version = ''
  if (browser.ie) {
    version = 'IE ' + browser.ie
  } else {
    if (browser.firefox) {
      version = 'firefox ' + browser.firefox
    } else {
      if (browser.chrome) {
        version = 'chrome ' + browser.chrome
      } else {
        if (browser.opera) {
          version = 'opera ' + browser.opera
        } else {
          if (browser.safari) {
            version = 'safari ' + browser.safari
          } else {
            version = '未知浏览器'
          }
        }
      }
    }
  }
  return version
}
export default { getOS, getBrowse }
